package com.key.sys;

import org.hibernate.Session;

import com.key.org.model.Person;
import com.key.util.HibernateUtil;
import com.opensymphony.xwork2.Action;

public class LoginAction implements Action {
	private String username;
	private String password;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String execute() throws Exception {
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		Person person = new Person();
		person.setUserName(username);
		person.setPassword(password);
		session.save(person);
		session.getTransaction().commit();
		if (username.equals("struts2")) {
			return "loginSuccess";
		} else {
			return "loginFailure";
		}
	}
}
